package com.geper.pattern.proxy;

import java.lang.reflect.Method;

/**
 * @author: lsy
 * @date: 2020-03-02 10:35
 * @description: HomeWorkDynamicProxyHandler
 */
public class HomeWorkDynamicProxyHandler implements HomeWorkInvocationHandler{

    private Object target;

    public Object getInstance(Object target) throws ClassNotFoundException {
        this.target = target;
        Class<?>[] interfaces = target.getClass().getInterfaces();
        return HomeWorkDynamicProxy.newProxyInstance(new HomeWorkClassLoader(), interfaces, this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object invoke = method.invoke(this.target, args);
        after();
        return invoke;
    }

    private void before(){
        System.out.println("找对象前");
    }

    private void after(){
        System.out.println("找对象后");
    }


}
